package com.cooksys.film_rental.bo.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cooksys.film_rental.bo.LanguageBo;
import com.cooksys.film_rental.dao.LanguageDao;
import com.cooksys.film_rental.model.Film;
import com.cooksys.film_rental.model.Language;

@Service("LanguageBo")
public class LanguageBoImpl implements LanguageBo {

	@Autowired(required = true)
	LanguageDao languageDao;

	@Override
	public Language getLanguageByLanguageId(Byte languageId) {
		return this.languageDao.getLanguageByLanguageId(languageId);
	}

	@Override
	public Language getLanguageByLanguageId(String languageId) {
		try {

			Byte languageIdAsByte = Byte.valueOf(languageId);
			return this.getLanguageByLanguageId(languageIdAsByte);

		} catch (NumberFormatException e) {

			System.err
					.println("Could not parse Byte value for languageId from string: "
							+ languageId);
			e.printStackTrace();
			System.err.println("Returning null value...");
			return null;

		}
	}

	@Override
	public List<Language> searchLanguagesByPartialName(String partialName) {
		return this.languageDao.searchLanguagesByPartialName(partialName);
	}

	@Override
	public Language getLanguageByFilm(Film film) {
		return this.languageDao.getLanguageByFilm(film);
	}

	@Override
	public Language getOriginalLanguageByFilm(Film film) {
		return this.languageDao.getOriginalLanguageByFilm(film);
	}

	@Override
	public List<Language> getAllLanguages() {
		return this.languageDao.getAllLanguages();
	}

}
